<template>
  <div class="mv-container">
    
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video id="video" controls autoplay :src="url"></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="detail.cover" alt />
          </div>
          <span class="name">{{detail.artistName}}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{detail.name}}</h2>
          <span class="date">发布：{{detail.publishTime}}</span>
          <span class="number">播放：{{detail.playCount}}次</span>
          <p class="desc">{{detail.desc}}</p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap">
        <p class="title">
          精彩评论
          <span class="number">({{hotComments.length}})</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,index) in hotComments" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div
                class="re-content"
                v-show="item.beReplied"
                v-for="(item2,index2) in beReplied"
                :key="index2"
              >
                <span class="name">{{item2.user.nickname}}：</span>
                <span class="comment">{{item2.content}}</span>
              </div>
              <div class="date">{{item.time}}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">
          最新评论
          <span class="number">({{total}})</span>
        </p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,index) in comments" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div
                class="re-content"
                v-show="item.beReplied"
                v-for="(item2,index2) in item.beReplied"
                :key="index2"
              >
                <span class="name">{{item2.user.nickname}}：</span>
                <span class="comment">{{item2.content}}</span>
              </div>
              <div class="date">{{item.time}}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="pageSize"
      ></el-pagination>
    </div>
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" v-for="(item,index) in similarMvs" :key="index">
            <div class="img-wrap">
              <img :src="item.cover" alt />
              <span class="iconfont icon-play" @click="id=item.id"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{item.playCount}}</div>
              </div>
              <span class="time">{{item.duration}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{item.name}}</div>
              <div class="singer">{{item.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "mv",
  data() {
    return {
      // 总条数
      total: 20,
      // 页码
      page: 1,
      // 页容量
      pageSize: 10,
      id: this.$route.query.id,
      url: "",
      detail: {},
      comments: [],
      hotComments: [],
      similarMvs: [],
    };
  },
  methods: {
    handleCurrentChange(val) {
      this.page = val;
    },
    playMv() {
      axios({
        url: "/autumnfish/mv/url",
        method: "get",
        params: {
          id: this.id,
        },
      }).then((res) => {
        this.url = res.data.data.url;
        document.getElementById("video").volume = 0.2;
        this.$parent.musicUrl = "";
      });
    },
    getComments() {
      //获得mv评论数据
      axios({
        url: "/autumnfish/comment/mv",
        method: "get",
        params: {
          id: this.id,
          limit: this.pageSize,
          offset: (this.page - 1) * this.pageSize,
        },
      }).then((res) => {
        this.comments = res.data.comments;
        if (this.page == 1) {
          this.total = res.data.total;
          this.hotComments = res.data.hotComments;
        }
      });
    },
    getSimilarMvs() {
      // 获得相似mv
      axios({
        url: "/autumnfish/simi/mv",
        method: "get",
        params: {
          mvid: this.id,
        },
      }).then((res) => {
        this.similarMvs = res.data.mvs;
        // 处理时长
        for (let i = 0; i < this.similarMvs.length; i++) {
          let duration = this.similarMvs[i].duration;

          let minute = parseInt(duration / 1000 / 60);
          let second = parseInt((duration / 1000) % 60);

          if (minute < 10) {
            minute = "0" + minute;
          }
          if (second < 10) {
            second = "0" + second;
          }

          duration = `${minute}:${second}`;
          this.similarMvs[i].duration = duration;
        }
      });
    },
    getMvDetails() {
      //获得mv详情
      axios({
        url: "/autumnfish/mv/detail",
        method: "get",
        params: {
          mvid: this.id,
        },
      }).then((res) => {
        this.detail = res.data.data;
      });
    },
  },
  watch: {
    page() {
      this.getComments();
    },
    id() {
      this.playMv();
      this.getMvDetails();
      this.getSimilarMvs();
      this.getComments();
    },
  },
  created() {
    this.playMv();
    this.getMvDetails();
    this.getSimilarMvs();
    this.getComments();
  },
};
</script>

<style></style>
